package com.itcodai.service.message;

import com.itcodai.config.message.ActiveMqConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

/** Topic消息消费者
 * @author c-fanqj
 * @date 2023/4/18
 * @apiNote
 */
@Service
public class TopicConsumer {

    private final Logger logger =
            LoggerFactory.getLogger(this.getClass());

    /**
     * 接收订阅消息
     * @param msg
     */
    // @JmsListener 注解默认只接收 queue 消息
    // 如果要接收topic 消息，需要设置 containerFactory
    @JmsListener(destination = ActiveMqConfig.TOPIC_NAME, containerFactory = "topicListenerContainer")
    public void receiveTopicMsg(String msg) {
        logger.info("Topic收到的消息为：{}", msg);
    }

}
